package com.fire.security.controller;

import com.fire.security.core.page.TableDataInfo;
import com.fire.security.domain.Report;
import com.fire.security.domain.Result;
import com.fire.security.dto.DeviceStatusCountDto;
import com.fire.security.service.ReportService;
import com.fire.security.utils.uuid.IdUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/report")
@RestController
public class ReportController extends BaseController {

    @Autowired
    private ReportService reportService;

    /*
     * 条件分页查询
     * */
    @GetMapping("/selectAllReport")
    public TableDataInfo ReportList(@Param("report") Report report) {
        startPage();
        List<Report> list = reportService.findAllReports(report);
        return getDataTable(list);
    }

    /*
     * 更新数据
     * */
    @PostMapping("/updateReport")
    public Result updateReport(Report report) {

        Result result = reportService.updateReportStatus(report);
        return result;
    }

    /*
     * 添加数据
     * */
    @PostMapping("/insertReport")
    public Result insertReport( Report report) {
//        report.setId(IdUtils.randomUUID());
        report.setImage("http://localhost:8088/img/"+report.getImage());
        Result result = reportService.insertReport(report);
        return result;
    }

    /*
     * 驳回
     * */
    @PostMapping("/back")
    public Result back(@RequestBody Report report) {
        Result result = reportService.back(report);
        return result;
    }

    /*
     * 删除数据
     * */
    @PostMapping("/deleteReportById")
    public Result deleteReportById(String id) {
        Result result = reportService.deleteReportById(id);
        return result;

    }
    @GetMapping("/countEventStatus")
    public List<DeviceStatusCountDto> deviceStatusCount()
    {
        return reportService.countEventByStatus();
    }
}
